home *** CD-ROM | disk | FTP | other *** search
/ Deutsche Edition 2 / Deutsche Edition 2.iso / mac / BILDSCHIRMSCHONER / AFTER DARK ADDS / Slinkicizer / Slinkicizer.p < prev   
Text File  |  1991-08-05  |  4KB  |  172 lines

  1. {Slinkicizer.p}
  2. {Some of this code is modeled after the After Dark Module "7.0fo"
  3. In the spirit of sharing please tear this apart and make more modules.
  4. Dan LaSota
  5. Ant Man! }
  6.  
  7. unit danz;
  8.  
  9. interface
  10.  
  11.     uses
  12.         Quickdraw, Sound, Files, Processes, Packages, Fonts,
  13.         Memory, Toolutils, OSUtils, GestaltEqu, GraphicsModuleTypes;
  14.  
  15.     function DoInitialize (var storage: Handle; blankRgn: rgnHandle; params: GMParamBlockPtr): OSErr;
  16.  
  17.     function DoBlank (storage: Handle; blankRgn: rgnHandle; params: GMParamBlockPtr): OSErr;
  18.  
  19.     function DoDrawFrame (storage: Handle; blankRgn: rgnHandle; params: GMParamBlockPtr): OSErr;
  20.  
  21.     function DoClose (storage: Handle; blankRgn: RgnHandle; params: GMParamBlockPtr): OSErr;
  22.  
  23.     function DoSetup (blankRgn: rgnHandle; message: integer; params: GMParamBlockPtr): OSErr;
  24.  
  25. implementation
  26.  
  27. type
  28. theData =
  29.     record
  30.         theRect: Rect;        { Holds the bounding rectangle for the circle. }
  31.         x: integer;
  32.         y: integer;
  33.         dh: integer;
  34.         dv: integer;
  35.         len: integer;
  36.         wid: integer;
  37.         shape:integer;
  38.         screenRect: Rect;
  39.     end;
  40.  
  41. thePtr = ^theData;
  42. theHandle = ^thePtr;
  43.  
  44. procedure eraseIT(r:rect;shape:integer);
  45.     begin
  46.         PenPat(black);
  47.         case shape of
  48.             1: FrameRect(r);
  49.             2: FrameOval(r);
  50.         end
  51.     end;
  52.  
  53. function getRect(x,y,length,width:integer): Rect;
  54.     var
  55.         a,b: integer;
  56.         box : rect;
  57.     begin
  58.         a := length div 2;
  59.         b := width div 2;
  60.         setRect(box,x-b,y-a,x+b,y+a);
  61.         getRect := box
  62.     end;
  63.     
  64. function DoInitialize (var storage: Handle; blankRgn: rgnHandle; params: GMParamBlockPtr): OSErr;
  65.     var od: theHandle;
  66.         i,j,k: integer;
  67.         osAttr: longInt;
  68.     begin
  69.         storage := NewHandle(sizeof(theData));
  70.         if MemError <> noErr then
  71.             begin
  72.                 DoInitialize := MemError;
  73.                 exit(DoInitialize);
  74.             end;
  75.         params^.qdGlobalsCopy^.qdRandSeed := TickCount;
  76.         od := theHandle(storage);
  77.         od^^.wid:=params^.controlValues[0];
  78.         od^^.len:=params^.controlValues[1];
  79.         od^^.shape:=params^.controlValues[2];
  80.         od^^.screenRect:=params^.monitors^.monitorList[0].bounds;
  81.         j := od^^.screenRect.right -200;
  82.         k := od^^.screenRect.bottom -200;
  83.         od^^.theRect:=getRect((abs(random mod k) + 100),(abs(random mod j) + 100),od^^.wid,od^^.len);
  84.         od^^.screenRect:=params^.monitors^.monitorList[0].bounds;
  85.         od^^.dh:=abs(random mod 10) + 1;
  86.         od^^.dv :=abs(random mod 10) + 1;
  87.         PenPat(white);
  88.         DoInitialize := noErr;
  89.         exit(DoInitialize);
  90.     end;
  91.  
  92.     function DoBlank (storage: Handle; blankRgn: rgnHandle; params: GMParamBlockPtr): OSErr;
  93.  
  94.     begin
  95.         {FillRgn(blankRgn, params^.qdGlobalsCopy^.qdBlack);}
  96.         DoBlank := noErr;
  97.     end;
  98.  
  99. function DoDrawFrame (storage: Handle; blankRgn: rgnHandle; params: GMParamBlockPtr): OSErr;
  100.     var od: theHandle;                    { Handle to the data (coerced from storage). }
  101.         r: Rect;                                { Rectangle of the current monitor. }
  102.         i,dx,dy,temp: integer;
  103.  
  104.     begin
  105.         od := theHandle(storage);
  106.         if od = nil then exit(DoDrawFrame);
  107.         dx:= od^^.dh;
  108.         dy := od^^.dv;
  109.         r:= od^^.theRect;
  110.         temp:=od^^.screenRect.right;
  111.         if (r.right>temp) then
  112.                 begin
  113.                     eraseIT(r,od^^.shape);
  114.                     OffSetRect(r,temp-r.right,0);
  115.                     dy:=abs(random mod 10) + 1;
  116.                     dy:=dy * (-1);
  117.                 end
  118.             else 
  119.                 begin
  120.                     temp:=od^^.screenRect.left ;
  121.                     if (r.left<temp) then
  122.                         begin
  123.                             eraseIT(r,od^^.shape);
  124.                             OffSetRect(r,-temp,0);
  125.                             dy:=abs(random mod 10) + 1;
  126.                             dy:=dy * (1);
  127.                         end
  128.                 end;
  129.         temp:=od^^.screenRect.top;
  130.         if (r.top<temp) then
  131.                 begin
  132.                     eraseIT(r,od^^.shape);
  133.                     OffSetRect(r,0,temp-r.top-1);
  134.                     dx:=dx * (-1);
  135.                 end
  136.             else 
  137.                 begin
  138.                     temp:=od^^.screenRect.bottom ;
  139.                     if (r.bottom>temp) then
  140.                         begin
  141.                             eraseIT(r,od^^.shape);
  142.                         {    OffSetRect(r,0,r.bottom-temp+1);  }
  143.                             dx:=abs(random mod 10) + 1;
  144.                             dx:=dx * (-1);
  145.                         end
  146.                 end;
  147.         PenPat(black);
  148.         eraseIT(r,od^^.shape);
  149.         OffSetRect(r,dy,dx);
  150.         od^^.dh:=dx;
  151.         od^^.dv:=dy;
  152.         od^^.theRect:=r;
  153.         PenPat(white);
  154.         case od^^.shape of
  155.             1: FrameRect(r);
  156.             2: FrameOval(r);
  157.         end;
  158.         DoDrawFrame := noErr;
  159.     end;
  160.  
  161. function DoClose (storage: Handle; blankRgn: RgnHandle; params: GMParamBlockPtr): OSErr;
  162.     begin
  163.         if storage <> nil then DisposHandle(storage);
  164.         DoClose := noErr;
  165.     end;
  166.  
  167. function DoSetup (blankRgn: rgnHandle; message: integer; params: GMParamBlockPtr): OSErr;
  168.     begin
  169.         DoSetup := noErr;
  170.     end;
  171.  
  172. end.